import requests

from contant.gaode import *


class GaodeTraceService:
    @classmethod
    def add_track(cls, sid: str, tid: str, trname: str):
        """
        新增轨迹
        :param sid: 服务编号
        :param tid: 终端编码
        :param trname: 轨迹名称
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'tid': tid,
            'trname': trname
        }
        # 发送HTTP请求
        response = requests.post(GAODE_TRACE_ADD, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def search_track(cls, sid: str, tid: str, trace_id: str):
        """
        新增轨迹
        :param sid: 服务编号
        :param tid: 终端编码
        :param trname: 轨迹名称
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'tid': tid,
            'trid': trace_id
        }
        # 发送HTTP请求
        response = requests.post(GAODE_TRACE_SEARCH, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data


    @classmethod
    def delete_track(cls, sid: str, tid: str, trid: str):
        """
        删除轨迹
        :param sid: 服务编号
        :param tid: 终端编码
        :param trid: 轨迹编码
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'tid': tid,
            'trid': trid
        }
        # 发送HTTP请求
        response = requests.post(GAODE_TRACE_DELETE, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def query_track_by_trid(cls, sid: str, tid: str, trid: str):
        """
        根据轨迹编码查询轨迹信息
        :param sid: 服务编号
        :param tid: 终端编码
        :param trid: 轨迹编码
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'tid': tid,
            'trid': trid
        }
        # 发送HTTP请求
        response = requests.get(GAODE_TRACE_SEARCH, params=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def query_track_by_time(cls, sid: str, tid: str, starttime: str, endtime: str):
        """
        根据时间查询轨迹信息
        :param sid: 服务编号
        :param tid: 终端编码
        :param starttime: 开始时间
        :parma endtime: 结束时间
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'tid': tid,
            'starttime': starttime,
            'endtime': endtime
        }
        # 发送HTTP请求
        response = requests.get(GAODE_TRACE_SEARCH, params=post_data)
        # 解析JSON响应
        data = response.json()
        return data
